<%--
  Created by IntelliJ IDEA.
  User: pc
  Date: 2023/11/14
  Time: 10:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form action="">
    <table>
        <input type="hidden" name="id">
        <tr>
            <th colspan="2">会员信息</th>
        </tr>
        <tr>
            <td>姓名</td>
            <td><input type="text" name="mname"></td>
        </tr>
        <tr>
            <td>性别</td>
            <td><input type="radio" name="mgender" value="男">男
                <input type="radio" name="mgender" value="女">女
            </td>
        </tr>
        <tr>
            <td>年龄</td>
            <td><input type="text" name="mage"></td>
        </tr>
        <tr>
            <td>家庭住址</td>
            <td><input type="text" name="maddress"></td>
        </tr>
        <tr>
            <td>Email</td>
            <td><input type="text" name="memail"></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="修改">
                <input type="button" value="重置" id="btnReset">
            </td>
        </tr>
    </table>
</form>
</body>
<script src="static/jquery-1.8.3.min.js"></script>
<script>
    $(function () {
        findById();
        $('#btnReset').click(function () {
            findById();
        })
    })

    function findById() {
        let id = location.search.substring(1)
        console.log(id)
        $.getJSON('/findById?'+id,data=>{
            // console.log(data)
            $('input[name=mname]').val(data['mname'])
            $('input[name=id]').val(data['id'])
            $('input[name=mage]').val(data['mage'])
            $('input[name=maddress]').val(data['maddress'])
            $('input[name=memail]').val(data['memail'])
            if(data['mgender']=='男'){
                $('input[value=男]').prop('checked',true);
            }else{
                $('input[value=女]').prop('checked',true);
            }
        })
    }

    $('form').submit(function () {
        $.ajax({
            url:'/update',
            method:'post',
            data:$('form').serialize(),
            dataType:'json',
            success:data=>{
                alert(data['msg'])
                if(data['status']==200){
                    location.href = 'index.jsp'
                }
            }
        })
        return false;
    })
</script>
</html>
